#include "collisionOptionsPanel.h"

#include <iostream>

CollisionOptionsPanel::CollisionOptionsPanel(QWidget *_parent) : QWidget(_parent){
    active = false;
    distanceError = 0.05;
    dampingFactor = 1;


    QCheckBox *activeCheckBox = new QCheckBox("Ativar");
    activeCheckBox->setChecked(active);
    connect(activeCheckBox, SIGNAL(toggled(bool)), this, SLOT(changeActive(bool)));

    QLabel *distanceErrorLabel = new QLabel(QString::fromUtf8("Erro no teste de distância:"));
    distanceErrorLabel->setEnabled(active);
    connect(activeCheckBox, SIGNAL(toggled(bool)), distanceErrorLabel, SLOT(setEnabled(bool)));

    QDoubleSpinBox *distanceErrorDoubleSpinBox = new QDoubleSpinBox();
    distanceErrorDoubleSpinBox->setRange(0.0, 1.0);
    distanceErrorDoubleSpinBox->setSingleStep(0.05);
    distanceErrorDoubleSpinBox->setDecimals(5);
    distanceErrorDoubleSpinBox->setValue(distanceError);
    distanceErrorDoubleSpinBox->setEnabled(active);
    connect(distanceErrorDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeDistanceError(double)));
    connect(activeCheckBox, SIGNAL(toggled(bool)), distanceErrorDoubleSpinBox, SLOT(setEnabled(bool)));


    QLabel *dampingFactorLabel = new QLabel(tr("Fator de amortecimento:"));
    dampingFactorLabel->setEnabled(active);
    connect(activeCheckBox, SIGNAL(toggled(bool)), dampingFactorLabel, SLOT(setEnabled(bool)));

    QDoubleSpinBox *dampingFactorDoubleSpinBox = new QDoubleSpinBox();
    dampingFactorDoubleSpinBox->setRange(0.00001, 1.0);
    dampingFactorDoubleSpinBox->setSingleStep(0.001);
    dampingFactorDoubleSpinBox->setDecimals(5);
    dampingFactorDoubleSpinBox->setValue(dampingFactor);
    dampingFactorDoubleSpinBox->setEnabled(active);
    connect(dampingFactorDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeDampingFactor(double)));
    connect(activeCheckBox, SIGNAL(toggled(bool)), dampingFactorDoubleSpinBox, SLOT(setEnabled(bool)));


    QHBoxLayout *distanceErrorLayout = new QHBoxLayout;
    distanceErrorLayout->addWidget(distanceErrorLabel);
    distanceErrorLayout->addWidget(distanceErrorDoubleSpinBox);

    QHBoxLayout *dampingFactorLayout = new QHBoxLayout;
    dampingFactorLayout->addWidget(dampingFactorLabel);
    dampingFactorLayout->addWidget(dampingFactorDoubleSpinBox);


    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(activeCheckBox);
    mainLayout->addLayout(distanceErrorLayout);
    mainLayout->addLayout(dampingFactorLayout);
	mainLayout->addStretch(1);

    setLayout(mainLayout);
}
